package com.example.academic_affairs_system.model.vo.courses;

import com.example.academic_affairs_system.model.entity.AasCourses;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * 课程的视图对象
 *
 * @author hjx
 * @since 2023/02/04 3:23 PM
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("课程的视图对象")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CoursesVO {
  @ApiModelProperty("课程id")
  private Long coursesId;

  @ApiModelProperty("课程名称")
  private String name;

  @ApiModelProperty("课程性质")
  private String type;

  @ApiModelProperty("课程描述")
  private String desc;

  @ApiModelProperty("课程人数")
  private Long size;

  public static CoursesVO buildByEntity(AasCourses aasCourses) {
    return CoursesVO.builder()
        .coursesId(aasCourses.getId())
        .name(aasCourses.getName())
        .type(aasCourses.getType())
        .desc(aasCourses.getDesc())
        .build();
  }

  public static List<CoursesVO> buildByEntities(List<AasCourses> aasCourses) {
    List<CoursesVO> list = new ArrayList<>();
    for (AasCourses aasCourse : aasCourses) {
      list.add(
          CoursesVO.builder()
              .coursesId(aasCourse.getId())
              .name(aasCourse.getName())
              .type(aasCourse.getType())
              .desc(aasCourse.getDesc())
              .build());
    }
    return list;
  }
}
